<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">


<head>
    <!--{include file='comm/header.tpl'}-->
    <!--{include file='comm/comm_editor.tpl'}-->
    <title>商品录入</title>
    <style>
		html{
			overflow-y:scroll;
			overflow:-moz-scrollbars-vertical;
		}
		.hotkinds{float:left;width:99%;margin-top:2px;margin-left:1%;height:auto;overflow:hidden;}
		.dl_hotkinds{margin:0 5px;padding:5px 0 0;height:28px;background:#FCFAF4;}
		.dl_hotkinds_1{margin:0 5px;padding:5px 0 0;height:28px;background:#ececec;}
		.dl_hotkinds_2{margin:0 5px;padding:5px 0 0;height:28px;}
		.dt_hotkinds{float:left;width:90px;height:22px;line-height:22px;text-align:left;margin-right:2px;display:inline;font-size:0.9pm;font-weight:bold;overflow:hidden;white-space:nowrap;}
		.dl_hotkinds dd{line-height:22px;}
		.list_nowrap{float:left;overflow:hidden;white-space:nowrap;}
		.div_header{background:#FFFFFF;border:1px solid #fff;}
		.exist_goods_extend th{background:#EAEAEA;text-align:center;font-weight:bold;}
		.exist_goods_extend th,.exist_goods_extend td{border:1px solid #CCCCCC;text-align:center;}
		.exist_goods_extend td{height:40px;}
	</style>
</head>

<body style="overflow-y:hidden;">

<!--{include file='comm/naviBanner.tpl'}-->

<div class="ebsig_container">
    <!--{include file='comm/menu.tpl'}-->
    <div class="comm_content">

        <div style="clear:both;"></div>
        <div class="select-box">
            <div onclick="goods.change(1);" id="select_1" class="selected">
                商品基本信息
            </div>
            <div onclick="goods.change(2);" id="select_2">
                商品规格
            </div>
            <div onclick="goods.change(3);" id="select_3">
                商品图片和描述
            </div>
            <div onclick="goods.change(4);" id="select_4">
                商品关键字
            </div>
            <div onclick="goods.change(5);" id="select_5">
                商品标签
            </div>
            <div onclick="goods.change(6);" id="select_6">
                商品扩展属性
            </div>
        </div>

        <form name="goodsAdd_from" id="goodsAdd_from">
	        <!--商品基本信息-->
	        <div class="items clearfix" id="goods_base_info" style="width:100%;">
	            <h2 style="" class="tal">基本资料</h2>
				<div class="allTextTime" style="padding:10px 0px 10px 10px;">
					<div style="margin:8px 0" class="input-group">
						<span style="width: 110px;" class="input-group-addon">商品名称：</span>
						<input type="text" value="" placeholder="请输入商品名称【必填项】" name="goodsName" id="goodsName" class="form-control hasDatepicker" style="padding-left:8px;">
					</div>
					<div style="margin:8px 0" class="input-group">
						<span style="width: 110px;" class="input-group-addon">商品品牌：</span>
						<select placeholder="商品品牌" name="brandID" id="brandID" class="form-control hasDatepicker" style="width:147px;padding-left:8px;">
							<option value="0" style="padding-left:8px;">请选择</option>
							<!--{foreach from=$goods_info->goodsBrand item=brand}-->
								<option value="<!--{$brand->brandID}-->" style="padding-left:8px;"><!--{$brand->brandName}--></option>
							<!--{/foreach}-->
						</select>
					</div>
					<div style="margin:8px 0" class="input-group">
						<span style="width: 110px;" class="input-group-addon">商品单位：</span>
						<select placeholder="商品单位" name="unitID" id="unitID" class="form-control hasDatepicker" style="width: 147px;padding-left:8px;">
							<option value="0" style="padding-left:8px;">请选择</option>
							<!--{foreach from=$goods_info->goods_unit item=unit}-->
							<option value="<!--{$unit->unitID}-->" style="padding-left:8px;"><!--{$unit->unitName}--></option>
							<!--{/foreach}-->
						</select>
					</div>
					<div style="margin:8px 0" class="input-group">
						<span style="width: 110px;" class="input-group-addon">店铺：</span>
						<span placeholder="店铺" class="form-control hasDatepicker" style="padding-left:8px;">
							<!--{foreach from=$goods_info->shopInfo item=shops}-->
								<div style="height:26px;line-height:26px;width:180px;float:left;">
									<input type="checkbox" name="shopID" value="<!--{$shops->shopID}-->" checked> <!--{$shops->title}-->
								</div>
							<!--{/foreach}-->
						</span>
					</div>
					<div style="margin:8px 0" class="input-group">
						<span style="width: 110px;" class="input-group-addon">商品保质期：</span>
						<input type="text" value="" placeholder="请输入商品保质期" name="shelfLife" id="shelfLife" class="form-control hasDatepicker" style="padding-left:8px;">
					</div>
					<div style="margin:8px 0;" class="input-group">
	                    <span style="width:110px;" class="input-group-addon">商品简述：</span>
	                    <textarea placeholder="请输入商品简述" class="form-control tab_ar" id="brief" name="brief" style="width:500px;height:80px;padding-left:8px;"></textarea>
	                </div>
	                <div style="margin:8px 0;" class="input-group">
	                    <span style="width:110px;" class="input-group-addon">商品备注：</span>
	                    <textarea placeholder="请输入商品备注" class="form-control tab_ar" id="memo" name="memo" style="width:500px;height:80px;padding-left:8px;"></textarea>
	                </div>
				</div>
	        </div>
	
	        <!--商品规格-->
	        <div class="items clearfix" id="goods_spec_info" style="display:none;width:100%;">
	            <h2 class="tal">商品规格</h2>
	            <div class="allTextTime" style="padding:10px 0px 10px 10px;">
					<div style="margin:8px 0" class="input-group">
						<span style="width: 110px;" class="input-group-addon">市场价：</span>
						<input type="text" value="" placeholder="请输入商品市场价【必填项】" name="marketPrice" id="marketPrice" class="form-control hasDatepicker" style="padding-left:8px;">
					</div>
					
					<div style="margin:8px 0" class="input-group">
						<span style="width: 110px;" class="input-group-addon">销售价：</span>
						<input type="text" value="" placeholder="请输入商品销售价【必填项】" name="salePrice" id="salePrice" class="form-control hasDatepicker" style="padding-left:8px;">
					</div>
					
					<div style="margin:8px 0" class="input-group">
						<span style="width: 110px;" class="input-group-addon">商品重量(KG)：</span>
						<input type="text" value="" placeholder="请输入商品重量【必填项】" name="goodsWeight" id="goodsWeight" class="form-control hasDatepicker" style="padding-left:8px;">
					</div>
					
					<div style="margin:8px 0" class="input-group">
						<span style="width: 110px;" class="input-group-addon">库存：</span>
						<input type="text" value="" placeholder="请输入商品库存【默认为0】" name="goodsStock" id="goodsStock" class="form-control hasDatepicker" style="padding-left:8px;">
					</div>
					
					<div style="margin:8px 0" class="input-group">
						<span style="width: 110px;" class="input-group-addon">商家编码：</span>
						<input type="text" value="" placeholder="请输入商家编码【必填项】" name="externalNo" id="externalNo" class="form-control hasDatepicker" style="padding-left:8px;">
					</div>	
					
					<div class="extend_category">
						<div style="margin:8px 0" class="input-group goodsCategory_1">
							
							<span style="width: 110px;" class="input-group-addon">商品分类：</span>
							<select placeholder="商品大分类" name="bigCategoryID_1" id="bigCategoryID_1" class="form-control hasDatepicker" onchange="goods.getCategorySpec(1,1);" style="width: 147px;padding-left:8px;">
								<option value="0" style="padding-left:8px;">请选择</option>
		                        <!--{foreach from=$goods_info->bigArray item=big}-->
		                        	<option value="<!--{$big->bigCategoryID}-->" style="padding-left:8px;"><!--{$big->description}--></option>
		                        <!--{/foreach}-->
							</select>
							&nbsp;
							<select placeholder="商品中分类" name="midCategoryID_1" id="midCategoryID_1" class="form-control hasDatepicker" onchange="goods.getCategorySpec(2,1);" style="width: 147px;padding-left:8px;">
								<option value="0" style="padding-left:8px;">请选择</option>
							</select>
							&nbsp;
							<select placeholder="商品小分类" name="smallCategoryID_1" id="smallCategoryID_1" class="form-control hasDatepicker" style="width: 147px;padding-left:8px;">
								<option value="0" style="padding-left:8px;">请选择</option>
							</select>
							<img onclick="goods.addCategory(1, 1)" src="/quanliadmin/docroot/images/bag_open.gif" style="height:10px;line-height:10px;cursor:pointer;margin-left:18px;">
						</div>
						
					</div>
				</div>
	        </div>
	
	        <!--商品图片和详情-->
	        <div id="goods_picture_info" style="display:none;width:100%;">
	            <div class="items clearfix" style="width:100%;">
	                <h2 style="" class="tal">商品展示图片</h2>
	                <div class="items2">
	                    <div>
	                        <table>
	                            <tr>
	                                <td style="width:20%;">
	                                    <div style="width:100%;">
	                                        <div style="width:100%;height:130px;border:1px solid #E2D9D9;">
	                                            <image src="/quanliadmin/docroot/images//system/comm_default.jpg" id="img_1" style="width:100%;height:100%;" ></image>
	                                        </div>
	                                        <div style="padding-top:5px;text-align: center;">
	                                            <input type="button" class="btn" value="删除" onclick="goods.deletePic(1);">&nbsp;
	                                            <input type="button" class="btn" value="上传" id="uploadPic_1">
	                                            <input type="hidden"  name="hidImg_1" id="hidImg_1" value="" >
	                                        </div>
	                                    </div>
	                                </td>
	                                <td style="width:20%;padding-left: 20px;">
	                                    <div style="width:100%;">
	                                        <div style="width:100%;height:130px;border:1px solid #E2D9D9;">
	                                            <image src="/quanliadmin/docroot/images//system/comm_default.jpg" id="img_2" style="width:100%;height:100%;" ></image>
	                                        </div>
	                                        <div style="padding-top:5px;text-align: center;">
	                                            <input type="button" class="btn" value="删除" onclick="goods.deletePic(2);">&nbsp;
	                                            <input type="button" class="btn" value="上传" id="uploadPic_2">
	                                            <input type="hidden"  name="hidImg_2" id="hidImg_2" value="" >
	                                        </div>
	                                    </div>
	                                </td>
	                                <td style="width:20%;padding-left: 20px;">
	                                    <div style="width:100%;">
	                                        <div style="width:100%;height:130px;border:1px solid #E2D9D9;">
	                                            <image src="/quanliadmin/docroot/images//system/comm_default.jpg" id="img_3" style="width:100%;height:100%;" ></image>
	                                        </div>
	                                        <div style="padding-top:5px;text-align: center;">
	                                            <input type="button" class="btn" value="删除" onclick="goods.deletePic(3);">&nbsp;
	                                            <input type="button" class="btn" value="上传" id="uploadPic_3">
	                                            <input type="hidden" name="hidImg_3" id="hidImg_3" value="" >
	                                        </div>
	                                    </div>
	                                </td>
	                                <td style="width:20%;padding-left: 20px;">
	                                    <div style="width:100%;">
	                                        <div style="width:100%;height:130px;border:1px solid #E2D9D9;">
	                                            <image src="/quanliadmin/docroot/images//system/comm_default.jpg" id="img_4" style="width:100%;height:100%;" ></image>
	                                        </div>
	                                        <div style="padding-top:5px;text-align: center;">
	                                            <input type="button" class="btn" value="删除" onclick="goods.deletePic(4);">&nbsp;
	                                            <input type="button" class="btn" value="上传" id="uploadPic_4">
	                                            <input type="hidden" name="hidImg_4" id="hidImg_4" value="" >
	                                        </div>
	                                    </div>
	                                </td>
	                                <td style="width:20%;padding-left: 20px;">
	                                    <div style="width:100%;">
	                                        <div style="width:100%;height:130px;border:1px solid #E2D9D9;">
	                                            <image src="/quanliadmin/docroot/images//system/comm_default.jpg" id="img_5" style="width:100%;height:100%;" ></image>
	                                        </div>
	                                        <div style="padding-top:5px;text-align: center;">
	                                            <input type="button" class="btn" value="删除" onclick="goods.deletePic(5);">&nbsp;
	                                            <input type="button" class="btn" value="上传" id="uploadPic_5">
	                                            <input type="hidden" name="hidImg_5" id="hidImg_5" value="" >
	                                        </div>
	                                    </div>
	                                </td>
	                            </tr>
	                        </table>
	                    </div>
	                </div>
	            </div>
	            <div class="items clearfix" style="width:100%;">
	                <h2 style="" class="tal">商品详情描述</h2>
	                <div class="items2">
	                    <div>
	                        <textarea name="description" id="description" style="width:100%;height:400px;visibility:hidden;"></textarea>
	                    </div>
	                </div>
	            </div>
	            <div style="margin-top:50px;"></div>
	        </div>
	
	        <!--商品关键字-->
	        <div class="items clearfix" id="goods_keywords_info" style="display:none;width:100%;">
	            <h2 style="" class="tal">商品关键字</h2>
	            <div class="items2">
	                <div>
	                    <table class="dl_hotkinds" id="js_hotkinds" style="width:100%;background:#FFFFFF">
	                        <tr>
	                            <td id="keyTD" style="text-align:left;height:30px;padding-bottom:20px;">
	                                <input type="text" name="keyWord" id="keyWord" value="" style="width:200px;">
	                                &nbsp;
	                                <input type="button" value="添加" class="btn" onclick="addKeyWords();">
	                            </td>
	                        </tr>
	                        <tr>
	                            <td id="keywordList"></td>
	                        </tr>
	                    </table>
	                </div>
	            </div>
	        </div>
	
	        <!--商品标签-->
	        <div id="goods_tag_info" class="items clearfix" style="display:none;width:100%;">
	            <h2 class="tal">商品标签</h2>
	            <div class="items2"></div>
	
	        </div>
	
	        <!--商品扩展属性-->
	        <div class="items clearfix" id="goods_ream" style="display:none;width:100%;">
	            <h2 class="tal">商品扩展属性</h2>
	            <div class="items2">
		            <div style="width:58%;height:45px;">
		                <input type="text" name="addExtendName" id="addExtendName" style="width:280px;">
		
		                <input type="text" name="addExtendVal" id="addExtendVal" style="width:280px;">
		
		                <input type="button" value="添加" class="btn" onclick="goods.addExtend();">
					</div>    
	                <div style="text-align:left;width:58%;">
		                <table class="exist_goods_extend" class="s" style="width: 100%;margin: 0 auto;">
		                    <thead>
								<tr>
									<th width="30%">属性名</th>
									<th width="40%">属性值</th>
									<th width="30%">操作</th>
								</tr>
		                    </thead>
		
							<tbody>
								<!--{if isset($extend_array)}-->
									<!--{foreach from=$extend_array item=extend}-->
										<tr>
											<td><!--{$extend}--></td>
											<td><input type="text" maxlength="100" style="width:90%;" parentName='<!--{$extend}-->' name="extend_val"></td>
											<td>
												<img onclick="goods.upMove(this);" style="cursor:pointer;" title="向上移动" src="/quanliadmin/docroot/images/icon_asc.gif">
												<img onclick="goods.downMove(this);" style="cursor:pointer;margin-left:12px;" title="向下移动" src="/quanliadmin/docroot/images/icon_desc.gif">
												<img onclick="goods.delMove(this);" style="cursor:pointer;margin-left:12px;" title="删除" src="/quanliadmin/docroot/images/icon_delete.gif">
											</td>	
										</tr>
									<!--{/foreach}-->
								<!--{/if}-->
							</tbody>
		                </table>   
	                </div>
	                
	            </div>
	        </div>

        </form>
        
        <div style="height:45px;"></div> 
        
        <div class="bottom_fixbox">
		    <div class="rectbox tac">
				<input type="button" onclick="goods.check();" class="btn" value="保存" />
		    </div>
		</div>

        </div>
</div>

</body>
</html>
<script>

	window.editor = KindEditor.create("#description");
	
	$("#flex").flexigrid({
        url:"",
        dataType: "json",
        colModel : [
            {display: "规格 <font color='red'>*</font>", width : 140, align: "center"},
            {display: "销售价 <font color='red'>*</font>", width : 140, align: "center"},
            {display: "市场价 <font color='red'>*</font>", width : 140, align: "center"},
            {display: "商品重量 <font color='red'>*</font>", width : 140, align: "center"},
            {display: "库存", width : 140, align: "center"},
            {display: "商家编码 <font color='red'>*</font>", width : 240, align: "center"},
        ],
        useRp: false,
        showTableToggleBtn: true,
    });
    
	var goods = {
		
		//添加分类 type添加or删除  num 第几个分类
		addCategory : function(type, num){
			
			if (type == 1) {
				if (!this.categoryNum) {
					this.categoryNum = parseInt(num) + 1;
				} else {
					this.categoryNum = parseInt(this.categoryNum) + 1;
				}
	
				this.categoryStr = $('#bigCategoryID_1').html();
				
				var html = '';
				html += '<div style="margin:8px 0" class="input-group goodsCategory_'+this.categoryNum+'">';
					html += '<span style="width: 110px;" class="input-group-addon">商品分类：</span>';
					html += '<select placeholder="商品大分类" name=bigCategoryID_'+this.categoryNum+' id=bigCategoryID_'+this.categoryNum+' class="form-control hasDatepicker" onchange=goods.getCategorySpec(1,'+this.categoryNum+'); style="width: 147px;padding-left:8px;">';
						html += this.categoryStr;
					html += '</select>';
					html += '&nbsp;';
					html += '<select placeholder="商品中分类" name=midCategoryID_'+this.categoryNum+' id=midCategoryID_'+this.categoryNum+' class="form-control hasDatepicker" onchange=goods.getCategorySpec(2,'+this.categoryNum+'); style="width: 147px;padding-left:8px;margin-left:12px;">';
						html += '<option value="0" style="padding-left:8px;">请选择</option>';
					html += '</select>';
					html += '&nbsp;';
					html += '<select placeholder="商品小分类" name=smallCategoryID_'+this.categoryNum+' id=smallCategoryID_'+this.categoryNum+' class="form-control hasDatepicker" style="width: 147px;padding-left:8px;margin-left:12px;">';
						html += '<option value="0" style="padding-left:8px;">请选择</option>';
					html += '</select>';
					html += '<img onclick=goods.addCategory(0,'+this.categoryNum+') src="/quanliadmin/docroot/images/bag_close.gif" style="height:10px;line-height:10px;cursor:pointer;margin-left:18px;">';
				html += '</div>';
				
				$('.extend_category').append(html);
			} else {
				$('.goodsCategory_'+num).remove();
				$('#categoryTag_'+num).remove();
			}
			
		},
		
		upMove : function(obj){
        	var objParentTR = $(obj).parent().parent();
			var prevTR = objParentTR.prev();
			if (prevTR.length > 0) {
				prevTR.insertAfter(objParentTR);
			}
        },
        
        downMove : function(obj){
        	var objParentTR = $(obj).parent().parent();
			var nextTR = objParentTR.next();
			if (nextTR.length > 0) {
				nextTR.insertBefore(objParentTR);
			}
        },
        
        delMove : function(obj){
        	$(obj).parent().parent().remove();
        },
        
        addExtend : function(){
        	var addExtendName = E.trim($('#addExtendName').val());
        	var addExtendVal  = E.trim($('#addExtendVal').val());
        	
        	if (addExtendName == "") {
        		E.alert('请输入扩展属性名');
        		return false;
        	}
        	
        	if (addExtendVal == "") {
        		E.alert('请输入扩展属性值');
        		return false;
        	}
        	
        	//检查扩展属性是否重复
        	var repeatFlg  = 0;
        	var repeatName = '';
        	$('[name=extend_val]').each(function(k,v){
        		var extendName = $(v).attr('parentname');
        		
        		if (extendName == addExtendName) {
        			repeatFlg = 1;
        			repeatName = extendName;
        			return false;
        		}
        	})
        	
        	if (repeatFlg == 1) {
        		E.alert('商品扩展属性「'+repeatName+'」已经存在');
        		return false;
        	}
        	
        	var html = '';
        	html += '<tr>';
				html += '<td>'+addExtendName+'</td>';
				html += '<td><input type="text" maxlength="100" style="width:90%;" parentName='+addExtendName+' name="extend_val" value='+addExtendVal+'></td>';
				html += '<td>';
					html += '<img onclick="goods.upMove(this);" style="cursor:pointer;" title="向上移动" src="/quanliadmin/docroot/images/icon_asc.gif">';
					html += '<img onclick="goods.downMove(this);" style="cursor:pointer;margin-left:19px;" title="向下移动" src="/quanliadmin/docroot/images/icon_desc.gif">';
					html += '<img onclick="goods.delMove(this);" style="cursor:pointer;margin-left:18px;" title="删除" src="/quanliadmin/docroot/images/icon_delete.gif">';
				html += '</td>';
			html += '</tr>';
			
			$('.exist_goods_extend tbody').append(html);
			
			$('#addExtendName').val('');
        	$('#addExtendVal').val('')
        },
		
		//切换显示标签
		change: function(flg){
			if(flg == 1){	//商品基本信息
				$('#select_1').addClass('selected');
				$('#select_2').removeClass('selected');
				$('#select_3').removeClass('selected');
				$('#select_4').removeClass('selected');
				$('#select_5').removeClass('selected');
                $('#select_6').removeClass('selected');

				$('#goods_base_info').css('display', 'block');
				$('#goods_spec_info').css('display', 'none');
				$('#goods_picture_info').css('display', 'none');
				$('#goods_keywords_info').css('display', 'none');
				$('#goods_tag_info').css('display', 'none');
                $('#goods_ream').css('display', 'none');
				
			}else if(flg == 2){	//商品规格
				
				$('#select_1').removeClass('selected');
				$('#select_2').addClass('selected');
				$('#select_3').removeClass('selected');
				$('#select_4').removeClass('selected');
				$('#select_5').removeClass('selected');
                $('#select_6').removeClass('selected');
				
				$('#goods_base_info').css('display', 'none');
				$('#goods_spec_info').css('display', 'block');
				$('#goods_tag_info').css('display', 'none');
				$('#goods_picture_info').css('display', 'none');
				$('#goods_keywords_info').css('display', 'none');
                $('#goods_ream').css('display', 'none');
			}else if(flg == 3){ //图片和描述
				$('#select_1').removeClass('selected');
				$('#select_2').removeClass('selected');
				$('#select_3').addClass('selected');
				$('#select_4').removeClass('selected');
				$('#select_5').removeClass('selected');
                $('#select_6').removeClass('selected');
				
				$('#goods_base_info').css('display', 'none');
				$('#goods_spec_info').css('display', 'none');
				$('#goods_picture_info').css('display', 'block');
				$('#goods_keywords_info').css('display', 'none');
				$('#goods_tag_info').css('display', 'none');
                $('#goods_ream').css('display', 'none');
			}else if(flg == 4){ //商品关键字
				$('#select_1').removeClass('selected');
				$('#select_2').removeClass('selected');
				$('#select_3').removeClass('selected');
				$('#select_4').addClass('selected');
				$('#select_5').removeClass('selected');
                $('#select_6').removeClass('selected');
				
				$('#goods_base_info').css('display', 'none');
				$('#goods_spec_info').css('display', 'none');
				$('#goods_picture_info').css('display', 'none');
				$('#goods_keywords_info').css('display', 'block');
				$('#goods_tag_info').css('display', 'none');
                $('#goods_ream').css('display', 'none');
			}else if(flg == 5){ //商品标签
				$('#select_1').removeClass('selected');
				$('#select_2').removeClass('selected');
				$('#select_3').removeClass('selected');
				$('#select_4').removeClass('selected');
				$('#select_5').addClass('selected');
				$('#select_6').removeClass('selected');

				$('#goods_base_info').css('display', 'none');
				$('#goods_spec_info').css('display', 'none');
				$('#goods_picture_info').css('display', 'none');
				$('#goods_keywords_info').css('display', 'none');
				$('#goods_tag_info').css('display', 'block');
                $('#goods_ream').css('display', 'none');
			}else if(flg == 6){

                $('#select_1').removeClass('selected');
                $('#select_2').removeClass('selected');
                $('#select_3').removeClass('selected');
                $('#select_4').removeClass('selected');
                $('#select_5').removeClass('selected');
                $('#select_6').addClass('selected');

                $('#goods_base_info').css('display', 'none');
                $('#goods_spec_info').css('display', 'none');
                $('#goods_picture_info').css('display', 'none');
                $('#goods_keywords_info').css('display', 'none');
                $('#goods_tag_info').css('display', 'none');
                $('#goods_ream').css('display', 'block');

            }
		},
		
		//根据当前分类查找下级分类
		getCategory : function(flg){
        	if(flg == 1){	//大分类
        		var bigID = $('#bigCategoryID').val();
        		if(bigID == 0){
        			$('#midCategoryID').html('<option value="0">请选择</option>');
        			$('#smallCategoryID').html('<option value="0">请选择</option>');
        		}else{
        			$('#midCategoryID').html('<option value="0">请选择</option>');
        			$('#smallCategoryID').html('<option value="0">请选择</option>');
        			
        			//ajax查询中分类信息
        			var bigObj = {'flg' : 1, 'id' : bigID};
	        		$.ajax({
	        			url : "/invokingAjax-backend/promotion/goodsSelector.ajax?operFlg=4",
	        			type : 'POST',
	        			data : bigObj,
						success: function(result) {
							result = eval('(' + result + ')');
							
							if(result != 1){
								var htmlStr = '<option value="0">请选择</option>';
								$.each(result, function(k, v){
									htmlStr += '<option value=' + k + '>' + v + '</option>'
								})
								
								$('#midCategoryID').html(htmlStr);
							}else if(result == 1){
								$('#midCategoryID').html('<option value="0">请选择</option>');
        						$('#smallCategoryID').html('<option value="0">请选择</option>');
							}
						}
	        		});
        		}
        	}else if(flg == 2){	//中分类
        		var bigID = $('#bigCategoryID').val();
        		var midID = $('#midCategoryID').val();
        		if(midID == 0)
        			$('#smallCategoryID').html('<option value="0">请选择</option>');
        		else{
        			//ajax查询小分类信息
        			var midObj = {'flg' : 2, 'id' : bigID + '_' + midID};
        			$.ajax({
	        			url : "/invokingAjax-backend/promotion/goodsSelector.ajax?operFlg=4",
	        			type : 'POST',
	        			data : midObj,
						success: function(result) {
							result = eval('(' + result + ')');
							
							if(result != 1){
								var htmlStr = '<option value="0">请选择</option>';
								$.each(result, function(k, v){
									htmlStr += '<option value=' + k + '>' + v + '</option>'
								})
								
								$('#smallCategoryID').html(htmlStr);
							}else if(result == 1)
								$('#smallCategoryID').html('<option value="0">请选择</option>');
						}
	        		});
        		}
        	}
        },
        
        //查询子分类 flg：分类级别  num：第几个分类
        getCategorySpec : function(flg, num){
        	
        	if(flg == 1){	//大分类
        		var bigID = $('#bigCategoryID_'+num).val();
        		
        		if(bigID == 0){
        			$('#midCategoryID_'+num).html('<option value="0" style="padding-left:8px;">请选择</option>');
        			$('#smallCategoryID_'+num).html('<option value="0" style="padding-left:8px;">请选择</option>');
        		}else{

        			//ajax查询中分类信息
        			var bigObj = {'flg' : 1, 'id' : bigID};
	        		$.ajax({
	        			url : "/invokingAjax-backend/promotion/goodsSelector.ajax?operFlg=4",
	        			type : 'POST',
	        			data : bigObj,
						success: function(result) {
							result = eval('(' + result + ')');
							
							if(result != 1){
								var htmlStr = '<option value="0" style="padding-left:8px;">请选择</option>';
								$.each(result, function(k, v){
									htmlStr += '<option value=' + k + ' style="padding-left:8px;">' + v + '</option>'
								})
								
								$('#midCategoryID_'+num).html(htmlStr);
							}else if(result == 1){
								$('#midCategoryID_'+num).html('<option value="0" style="padding-left:8px;">请选择</option>');
        						$('#smallCategoryID_'+num).html('<option value="0" style="padding-left:8px;">请选择</option>');
							}
						}
	        		});
        		}
        	}else if(flg == 2){	//中分类
        		var bigID = $('#bigCategoryID_'+num).val();
        		var midID = $('#midCategoryID_'+num).val();

        		if(midID == 0)
        			$('#smallCategoryID_'+num).html('<option value="0" style="padding-left:8px;">请选择</option>');
        		else{
        			
        			//ajax查询小分类信息
        			var midObj = {'flg' : 2, 'id' : bigID + '_' + midID};
        			$.ajax({
	        			url : "/invokingAjax-backend/promotion/goodsSelector.ajax?operFlg=4",
	        			type : 'POST',
	        			data : midObj,
						success: function(result) {
							result = eval('(' + result + ')');
							
							if(result != 1){
								var htmlStr = '<option value="0" style="padding-left:8px;">请选择</option>';
								$.each(result, function(k, v){
									htmlStr += '<option value=' + k + ' style="padding-left:8px;">' + v + '</option>'
								})
								
								$('#smallCategoryID_'+num).html(htmlStr);
							}else if(result == 1)
								$('#smallCategoryID_'+num).html('<option value="0" style="padding-left:8px;">请选择</option>');
						}
	        		});
        		}
        	}
        	
        	goods.submitTag(num);
        },
        
        //上传图片
        uploadPic:function( flg ){
            E.open("/quanliadmin/app/uploads/goodsImage.php?flg=" + flg, "上传", {height: 200,width: 800, top: 50, left: 150});
        },

        //删除商品图片
        deletePic:function( flg ){
            $('#img_' + flg).attr('src', '/quanliadmin/docroot/images//system/comm_default.jpg');
            $('#hidImg_' + flg).val('');
        },

        //显示图片
        showImage:function( imageUrl , flg ){
            $('#img_' + flg).attr('src', '/quanliadmin/docroot/images/goods/' + imageUrl);
            $('#hidImg_' + flg).val(imageUrl);
        },
        
        //加载分类对应标签
        submitTag : function(num){
        	
        	var bigCategoryID   = $.trim($("#bigCategoryID_"+num).val());
        	var midCategoryID   = $.trim($("#midCategoryID_"+num).val());
        	var smallCategoryID = $.trim($("#smallCategoryID_"+num).val());

        	var specArr = {'bigCategory' : bigCategoryID,'midCategoryID' : midCategoryID, 'smallCategoryID' : smallCategoryID, 'num' : num};

       		$.ajax({
       			type:"POST",
       			url:"/invokingAjax-backend/goods/goodsAdd.ajax?operFlg=5",
        		dataType:"JSON",
        		data: specArr,
        		success:function(result_obj){
					
        			$('#categoryTag_'+result_obj.num).remove();
        			
					if (result_obj.code == 200) {
						$('#goods_tag_info .items2').append(result_obj.message);
						
						//去除重复
						$('[title^=repeatTag_]').each(function(k, v){
							
							var repeatTagValue = $(this).attr('value');
							
							var repeatTagAmount = $('[title=repeatTag_'+repeatTagValue+']');
							if (repeatTagAmount.length > 1) {
								repeatTagAmount.each(function(k, v) {
									if (k >= 1) {
										$(this).remove();
									}
								})
							}
						})
					}
        		}	
        	});	
        },
       
        //检查保存的数据
        check: function() {
        	
            this.dt = E.getFormValues('goodsAdd_from');
            
            var error_msg = '';
            
            if (this.dt.goodsName == '') {
                error_msg += "商品名称不能为空<br />";
            }
                
            //检查店铺
            if ($('[name=shopID]:checked').length <= 0) {
            	error_msg += "请选择店铺信息<br />";
            }
            
         	//市场价
         	if (!E.isNum(this.dt.marketPrice) || this.dt.marketPrice <= 0) {
                error_msg += "商品市场价必须大于0元<br />";
            }	
            
            //销售价
            if (!E.isNum(this.dt.salePrice) || this.dt.salePrice <= 0) {
                error_msg += "商品销售价必须大于0元<br />";
            }
            
            //商品重量
            if (!E.isNum(this.dt.goodsWeight) || this.dt.goodsWeight < 0) {
                error_msg += "商品重量必须大于等于0千克<br />";
            }
            
            //商家编码
            if (this.dt.externalNo == '') {
                error_msg += "请填写商家编码<br />";
            }

            //商品分类
            this.save_category_array = [];
            
            if (this.categoryNum) {
            	
            	//说明就多个分类
            	var check_category_array = [];
            	var check_category_str = '';
            	
            	for ( var i=1; i<=this.categoryNum; i++ ) {
            		var goodsCategoryLength = $('.goodsCategory_'+i).length;
            		if (goodsCategoryLength >= 1) {
            			
            			var bigCategoryID = $('#bigCategoryID_'+i).val();
            			var midCategoryID = $('#midCategoryID_'+i).val();
            			var smallCategoryID = $('#smallCategoryID_'+i).val();
            			
            			this.save_category_array.push([bigCategoryID, midCategoryID, smallCategoryID]);
            			
            			if (bigCategoryID == '' || bigCategoryID == 0) {
		            		check_category_str += '请选择大分类<br/>';
		            	}
		            	
		            	if (midCategoryID == '' || midCategoryID == 0) {
		            		check_category_str += '请选择中分类<br/>';
		            	}
		            	
		            	var categoryStr = bigCategoryID + midCategoryID + smallCategoryID;

		            	if (check_category_array.length == 0) {
		            		check_category_array.push(categoryStr);
		            	} else {
		            		for (var j=0; j<check_category_array.length; j++) {
		            			if (check_category_array[j] == categoryStr) {
		            				check_category_str += '分类不能重复选择<br/>';
		            			}
		            		}
		            	}
		            	
		            	if (check_category_str != '') {
		            		break;
		            	}
            		}
            	}
            	
            	if (check_category_str != '') {
            		error_msg += check_category_str;
            	}
            	
            } else {
            	
            	//说明就一个分类
            	var bigCategoryID = $('#bigCategoryID_1').val();
            	var midCategoryID = $('#midCategoryID_1').val();
            	var smallCategoryID = $('#smallCategoryID_1').val();
            	
            	this.save_category_array.push([bigCategoryID, midCategoryID, smallCategoryID]);
            	
            	if (bigCategoryID == '' || bigCategoryID == 0) {
            		error_msg += '请选择大分类<br/>';
            	}
            	
            	if (midCategoryID == '' || midCategoryID == 0) {
            		error_msg += '请选择中分类<br/>';
            	}
            }
            
            //扩展属性
			var emptyFlg = 0;
			$('[name=extend_val]').each(function(k,v){
   				var extendVal = E.trim($(v).val());
   				if (extendVal == '') {
   					emptyFlg = 1;
   					return false;
   				}
			})
			
			if (emptyFlg == 1) {
				error_msg += '请输入扩展属性值<br/>';
			}
				
            if (error_msg != '') {
                E.alert(error_msg);
            } else {
                E.confirm("您确认要添加商品信息吗？", "goods.add");
            }    
        },

        //保存
        add: function() {
        	
        	editor.sync();
        	
        	//图片和详情信息
        	var description = $('#description').val();
        	var hidImg_1    = $.trim($('#hidImg_1').val());
        	var hidImg_2    = $.trim($('#hidImg_2').val());
        	var hidImg_3    = $.trim($('#hidImg_3').val());
        	var hidImg_4    = $.trim($('#hidImg_4').val());
        	var hidImg_5    = $.trim($('#hidImg_5').val());
        	var goodsImg = {
        		'hidImg_1' 	  : hidImg_1, 
        		'hidImg_2' 	  : hidImg_2, 
        		'hidImg_3' 	  : hidImg_3, 
        		'hidImg_4' 	  : hidImg_4, 
        		'hidImg_5' 	  : hidImg_5,
        		'description' : description
        	};

        	//关键字信息
        	var goodsKeyWord = new Array();
            $("input[name='addedKeywords']").each(function(k,v){
                var value = v.value;
                var t = v.checked;

                if( t == true ){
                    goodsKeyWord.push(value);
                }

            })
            
            //标签
            var goodsTag = [];
            $("input[name=tag]").each(function(k,v){
                var value = v.value;
                var t = v.checked;

                if( t == true ){
                    goodsTag.push(value);
                }
            })

            //商品扩展属性
            var goodsExtend = [];
            $('[name=extend_val]').each(function(k,v){
        		var extendName = $(v).attr('parentname');
        		var extendVal = E.trim($(v).val());
        		if (extendVal != '') {
        			goodsExtend.push([extendName,extendVal]);
        		}
        	})
			
        	var goodsData = {goodsBase : this.dt, goodsCategory : this.save_category_array, goodsImg : goodsImg, goodsKeyWord : goodsKeyWord, goodsTag : goodsTag, goodsExtend : goodsExtend};

        	E.loadding.open('请稍等...');
        	
        	//ajax提交数据
            $.ajax({
                type: 'POST',
                url: "/invokingAjax-backend/goods/goodsAdd.ajax?operFlg=3",
                dataType: "JSON",
                data: goodsData,
                success: function( result_obj ) {
                	E.loadding.close();
                    if(result_obj.code == 200){
                    	E.alert(result_obj.message, 2, 'E.refresh');

                    }else {
                        E.alert(result_obj.message);
                    }    
                }
            });
        }

	}
	
	//添加关键词
    function addKeyWords(){
        var keyWord = $.trim($("#keyWord").val());

        if( keyWord == '' ){
            E.alert('请输入关键字');
            return false;
        }

        //校验加入的关键字是否已经添加
        var exist = false;

        if( $("#keywordList").html() != '' ){

            $("input[name='addedKeywords']").each(function(){

                var objValue = $(this).val();

                if( objValue == keyWord ){
                    E.alert('关键字「' + objValue + '」已存在');
                    exist = true;
                }
            })

        }
        
        if( !exist ){
            document.getElementById('keywordList').innerHTML += '&nbsp;&nbsp;' +
            '<div style="width:450px;height:30px;background:#FFFFFF" class="list_nowrap">' +
            '<input type="checkbox" checked name="addedKeywords" value="' + keyWord + '"> ' + keyWord + "</div>";
            $("#keyWord").val("") ;
           
        }
		 $("#keyWord").select();
    }
    
    KindEditor.ready(function(K) {
        var editor = K.editor({
            allowFileManager : true,
            uploadJson: '/framework/kindeditor/php/upload_json.php?act=userdefined'
        });
        
        $(document).on('click','#uploadPic_1',function(){
            editor.loadPlugin('image', function() {
                editor.plugin.imageDialog({
                    showRemote : false,
                    clickFn : function(url) {
                    	//对url进行操作
                    	var urlArray = url.split('/');
                    	var lastPic = urlArray.pop();					
                    	
                    	$('#img_1').attr('src', url);
			            $('#hidImg_1').val(lastPic);
                        editor.hideDialog();
                    }
                });
            });
        });

        $(document).on('click','#uploadPic_2',function(){
            editor.loadPlugin('image', function() {
                editor.plugin.imageDialog({
                    showRemote : false,
                    clickFn : function(url) {
                    	//对url进行操作
                    	var urlArray = url.split('/');
                    	var lastPic = urlArray.pop();					
                    	
                    	$('#img_2').attr('src', url);
			            $('#hidImg_2').val(lastPic);
                        editor.hideDialog();
                    }
                });
            });
        });
        
        $(document).on('click','#uploadPic_3',function(){
            editor.loadPlugin('image', function() {
                editor.plugin.imageDialog({
                    showRemote : false,
                    clickFn : function(url) {
                    	//对url进行操作
                    	var urlArray = url.split('/');
                    	var lastPic = urlArray.pop();					
                    	
                    	$('#img_3').attr('src', url);
			            $('#hidImg_3').val(lastPic);
                        editor.hideDialog();
                    }
                });
            });
        });
        
        $(document).on('click','#uploadPic_4',function(){
            editor.loadPlugin('image', function() {
                editor.plugin.imageDialog({
                    showRemote : false,
                    clickFn : function(url) {
                    	//对url进行操作
                    	var urlArray = url.split('/');
                    	var lastPic = urlArray.pop();					
                    	
                    	$('#img_4').attr('src', url);
			            $('#hidImg_4').val(lastPic);
                        editor.hideDialog();
                    }
                });
            });
        });
        
        $(document).on('click','#uploadPic_5',function(){
            editor.loadPlugin('image', function() {
                editor.plugin.imageDialog({
                    showRemote : false,
                    clickFn : function(url) {
                    	//对url进行操作
                    	var urlArray = url.split('/');
                    	var lastPic = urlArray.pop();					
                    	
                    	$('#img_5').attr('src', url);
			            $('#hidImg_5').val(lastPic);
                        editor.hideDialog();
                    }
                });
            });
        });

    });
</script>